#!/bin/bash -e

# help to using this tool
# mkdir custom, and push the files into it, remind to rename them as the tree in README.md

# example command: 
# 1. bash run.sh i custom/fw_dir
# 2. bash run.sh b custom/fw_dir

otatools=$(realpath ./otatools/releasetools)
options="--block"
fw_dir=$2

if [ -z "$fw_dir" ];then 
fw_src=../custom/fw/src.zip
fw_tgt=../custom/fw/tgt.zip # you can replace the system.img and system.map from src.zip, system.map is made from mkext4fs -B system.map
out=../custom/fw/out.zip
else
fw_src=$(realpath "$fw_dir")/src_archos
fw_tgt=$(realpath "$fw_dir")/tgt_archos
out=$(realpath "$fw_dir")/update-block-v3.zip
fi

if [ $# -lt 1 ];then
	echo "<bash> <run.sh> <block/incre>"
	exit -1
fi

if [ "$1" == "block" -o "$1" == "b" ];then
	options="--block -v -2"
	fw_tgt=
elif [ "$1" == "incre" -o "$1" == "i" ];then
	options="--block -v -2 -i"
fi


mycommand="pushd otatools; python -B $otatools/ota_from_target_files $options $fw_src $fw_tgt $out; popd"
eval $mycommand

echo "your command is: "
echo $mycommand
